<!-- add by lty 20181222 -->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>设备交接清单</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<link rel="stylesheet" href="http://g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<link rel="stylesheet" href="./css/common.css">
<link rel="stylesheet" href="./css/hardware.css">
<!-- <link rel="stylesheet" type="text/css" href="./css/sm.css">
<link rel="stylesheet" type="text/css" href="./css/sm-extend.css"> -->

<script src="../js/jquery-1.8.3.min.js"></script>
<script src="./js/zepto.js"></script>
<script src="./js/sm.js"></script>
<script src="./js/sm-extend.js"></script>
<script type="text/javascript">
window.$$=window.Zepto = Zepto;
</script>
</head>
<body>
	<div class="page" style="overflow-y: scroll;">
		<header class="bar bar-nav">
			<a class="button button-link button-nav pull-left" href="javascript:window.history.back();" data-transition='slide-out'>
				<span class="icon icon-left"></span> 返回
			</a>
			<h1 class="title">硬设备交接清单</h1>
		</header>

	<!-- 主体内容 -->
	<div class="D_content" style="background: #fff;">
		<div class="D_content--wrap">
			<div id="listItemDiv">
			</div>
			<div class="list--change-line cl" style="text-align: center;">
				<span id="addItem" style="font-size: 18px;font-weight: 800;" >十</span>
			</div>
			
			<div class="list-remarks">
				<span class="re-txt" style="width:38%">清单所属房屋:</span>&nbsp;&nbsp;
				<select id="houseId" style="width:60%">
				</select>
			</div>
<!-- 			<div class="list-remarks"> -->
<!-- 				<span class="re-txt">房屋地址:</span>&nbsp;&nbsp; -->
<!-- 				<input type="text" id="houseAddress" /> -->
<!-- 			</div> -->
			<div class="list-remarks">
				<span class="re-txt">交接时间:</span>&nbsp;&nbsp;
				<input type="date" id="dealTime" />
			</div>
			<div class="list-remarks">
				<p class="re-txt">备注：</p>
				<textarea id="remark" placeholder="写点什么..."></textarea>
			</div>

			<!-- 保存 -->
			<div class="D_reserve--footer">
				<a href="javascript:toSave();" class="D_reserve--btn">保存</a>
			</div>
		</div>
		
		
	</div>
</div>

<script src="../js/common.js"></script>
<script src="./js/transferList.js"></script>
<script type="text/javascript">
var transferType = $.getUrlParam("transferType");	//0:租客交接清单 1:业主交接清单 
var listType = 1; 	//硬设备清单清单项
var houseId = $.getUrlParam("houseId");
var transferId = $.getUrlParam("transferId");	//所选租客id或房东id
var userId = $.getUrlParam("userId");	//所选租客id或房东id
var listName = $.getUrlParam("listName")||"附件一房屋硬件设备交接清单";


$(function(){

	transferList.initDefListItem( (listType=="1"?"3":"2") ); 	//加载默认清单项
	transferList.loadHouseList( $("#houseId"), (transferType=="0"?"1":"0") );	//加载可选房子列表
	
	$("#houseId").on("change",function(){
		$("#houseAddress").val($("#houseId").find("option[value="+$(this).val()+"]").attr("data-address"));
	});
	
	// 点击加减
	$("#listItemDiv").on("click",".change-box .add", function(){
		// 加1
		var _lastCount = $(this).siblings(".last-count");
		var _nowCount = Number(_lastCount.text()) + 1;
		_lastCount.text(_nowCount);
	});
	// 点击加减
	$("#listItemDiv").on("click",".change-box .reduce", function(){
		var _lastCount = $(this).siblings(".last-count");
		if (_lastCount.text() > 0) {
			var _nowCount = Number(_lastCount.text()) - 1;
			_lastCount.text(_nowCount);
		}
	});
	
	// 点击新增清单项
	$("#addItem").on("click",function(){
		var num = $("#listItemDiv").find("span.num").last().text()*1+1;
		var html = '<div class="list--change-line cl">'
					+	'<div class="fl">'
					+		'<span class="num">'+ num +'</span>、'
					+		'<input type="test" class="add-input name" placeholder="请输入">'
					+	'</div>'
					+	'<div class="change-box fr" style="padding: 0px;margin-left:5px;">'
					+		'<span class="delItem" style="font-weight: 900;color:red;" >一</span>'
					+	'</div>'
					+	'<div class="change-box fr">'
					+		'<span class="btn reduce">-</span> <span class="last-count">0</span>'
					+		'<span class="btn add">+</span>'
					+	'</div>'
				   + '</div>';
		$("#listItemDiv").append(html);
	});
	// 点击删除清单项
	$("#listItemDiv").on("click",".delItem",function(){
		$(this).parent().parent().remove();
		$("#listItemDiv").find("div.list--change-line.cl").each(function(i,n){
			$(n).find("span.num").text(i*1+1);
		 });
	});
});


function toSave(){
	if(!$("#houseId").val()){
		$$.toast("请选择房屋");
		return false;
	}
	if(!$("#houseId").val()){
		$$.toast("请输入房屋地址");
		return false;
	}
	if(!$("#dealTime").val()){
		$$.toast("请选择交接时间");
		return false;
	}
	if(transferId == undefined){
		transferId = getUUID();	//清单id
	}
	var listItemArr = new Array();
	$("#listItemDiv div.list--change-line.cl").each(function(i,n){
		var item = {
			itemId : getUUID(),
			transferId : transferId
		};
		item.num = $(n).find("span.num").text(); 
		item.name = $(n).find("span.name").text()||$(n).find("input.name").val();
		item.count = $(n).find("span.last-count").text();
		listItemArr.push( item );
	});
	var listItemArrStr = JSON.stringify(listItemArr);
	var listData = {
		transferId : transferId,
		houseId : $("#houseId").val(),
		userId : userId,
		listName : listName,
		dealTime : $("#dealTime").val(),
		remark : $("#remark").val(),
		transferType : transferType,
		listType : listType, 	//硬设备清单
		listItemArrStr : listItemArrStr
	}
	transferList.save(listData);
}
</script>
</body>
</html>